package br.com.caelum.vraptor.dao;

import javax.persistence.NoResultException;




import java.util.Date;
import java.sql.Time;

import br.com.caelum.vraptor.entidades.Laboratorio;
import br.com.caelum.vraptor.entidades.Professor;
import br.com.caelum.vraptor.entidades.Reserva;

public class ReservaDAO extends GenericJPADAO<Reserva>{
	
	public ReservaDAO() {
		this.persistentClass=Reserva.class;
	}
	
	public Reserva find(Date Data, Time Hrinicio, Time Hrfim, Laboratorio Lab, Professor Prof, String Descr){
		 try{
	         Reserva reserv = getEm().createQuery("select r from Reserva r where "
	         		+ "r.data=:data and r.hrinicio=:hrincio and r.hrfim=:hrfim and r.laboratorio=:lab"
	         		+ "and r.descr=:descr and r.professor=:prof", Reserva.class)
	                         .setParameter("Data", Data)
	                         .setParameter("Hrinicio", Hrinicio)
	                         .setParameter("Hrfim", Hrfim)
	                         .setParameter("Lab", Lab)
	                         .setParameter("Prof", Prof)
	                         .setParameter("Descr", Descr)
	                         .getSingleResult();
	         return reserv;
	         }
	 catch(NoResultException e){ 
		 return null; 
	 		}
		
		}

}


